package com.xbh.zzzTest;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.redis.Redis;
import com.jfinal.plugin.redis.RedisPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;

public class Test {

    private static final Logger logger = LoggerFactory.getLogger(Test.class.getName());

    public static void main(String[] args) {

        logger.info("1122334", "SLF4J");
    }

    public static void main3(String[] args) {

        RedisPlugin redisPlugin = new RedisPlugin("messageQueue", "127.0.0.1", 6379, 20000, "123456", 2);
        boolean start = redisPlugin.start();
        System.out.println(start);

        Jedis jedis = null;
        try {
            jedis = Redis.use("messageQueue").getJedis();
//            jedis.publish("myChannel", "服务器即将关闭，请下线存档 谢谢 ! ! !");

//            jedis.set("123", "123");
//            jedis.expire("123", 15);
            Long ttl = jedis.ttl("123");
            System.out.println(ttl);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (jedis != null) {
                jedis.close();
            }
        }
    }

    public static void main2(String[] args) {
        RedisPlugin redisPlugin = new RedisPlugin("testUUID", "127.0.0.1", 6379, 20000, "123456", 15);
        boolean start = redisPlugin.start();

        Jedis jedis = null;

        char[] chars = new char[36];
        for (int i = 0; i <= 9; i++) {
            chars[i] = (char) (i + 48);
        }
        for (int i = 10; i <= 35; i++) {
            chars[i] = (char) (i + 87);
        }

        System.out.println("准备工作完成 ~ ~ ~");

        for (int i = 0; i < chars.length; i++) {
            Set<String> keys = jedis.keys(chars[i] + "*");
//            查询对应key的数量
            int charsZize = keys.size();
            System.out.println(chars[i] + "*" + "  -->>  " + charsZize);

            if (charsZize > 0) {
                keys.forEach(s -> {
                    if (jedis.ttl(s) == -1) {
                        jedis.expire(s, 60);
                        System.out.println("处理完一个数据  -->>  " + s);
                    }
                });
            }

        }

        if (jedis.isConnected()) {
            jedis.close();
        }
    }

    public static void main1(String[] args) {
//        Thread0 thread0 = new Thread0();
//        Thread0 thread1 = new Thread0();
//        Thread0 thread2 = new Thread0();
//        thread0.start();
//        thread1.start();
//        thread2.start();
        RedisPlugin redisPlugin = new RedisPlugin("testUUID", "127.0.0.1", 6379, 20000, "123456", 15);
        boolean start = redisPlugin.start();

        Jedis jedis = Redis.use("testUUID").getJedis();

        for (int i = 0; i < 10000; i++) {
            String randomUUID = StrKit.getRandomUUID();
            System.out.println(randomUUID + "  -->  " + i);
            jedis.set(randomUUID, i + "");
        }


//        System.out.println();
    }

    public static void main0(String[] args) {

        List<Integer> list0 = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list0.add(i+1);
        }

        Function function = o -> ((Integer) o) + 1;

        Function function1 = o -> {
            if(((Integer) o) > 5){
                System.out.println("==========" + (Integer)o + 1);
                return (Integer)o + 1;
            }
            return o;
        };

//        Function function2 = o -> {
//            if(((Integer) o) > 5){
//                System.out.println("操作完成>>>>>>>>");
//            }
//            return o;
//        };

        for (int i = 0; i < list0.size(); i++) {

            list.add((Integer) function.compose(function1).apply(list0.get(i)));
        }

        list.forEach(System.out::println);
        

    }
    
    /**
     * <p> 
     * aaaaa
     * </p>
     * @param
     * @return: java.lang.String
     * @author: ZBoHang
     * @time: 2021/8/4 10:59
     */
    public static String test() {


        return null;
    }
}

